package com.kgcx.organization.service;

import com.kgcx.common.bean.RequestData;
import com.kgcx.common.constant.Cons;
import com.kgcx.dbutils.utils.PageUtils;
import com.kgcx.organization.domain.City;
import com.kgcx.organization.mapper.CityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class CityService {
    @Autowired
    private CityMapper cityMapper;

    public City getCity(Long kid) {
        return cityMapper.selectByPrimaryKey(kid);
    }

    public List<City> getCityList(RequestData rd) {
        PageUtils.page(rd);
        return cityMapper.getCityList(rd);
    }

    @Transactional(rollbackFor = Exception.class)
    public void addCity(City city) {
        cityMapper.insertSelective(city);
    }

    @Transactional(rollbackFor = Exception.class)
    public void updateCity(City city) {
        cityMapper.updateByPrimaryKeySelective(city);
    }

    @Transactional(rollbackFor = Exception.class)
    public void removeCity(Long kid) {
        City city = new City();
        city.setKid(kid);
        city.setStatus(Cons.COMMON_STATUS_DELETE);
        cityMapper.updateByPrimaryKeySelective(city);
    }
}
